#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using Agresso.Interface.Layer.Service;
using System.Collections;
using Agresso.Interface.Layer.Domain;

#endregion

namespace Agresso.Interface.Layer.Web
{
    public partial class FindCustomerForm : Form
    {
        acuheaderService m_service = new acuheaderService();
        SoftmarSupplierCustomerMappingForm m_parentForm;

        public FindCustomerForm(SoftmarSupplierCustomerMappingForm form)
        {
            InitializeComponent();
            m_parentForm = form;
            textBoxName.Text = m_parentForm.GetCompanyName().Trim();
        }
        private void FindCustomerForm_Load(object sender, EventArgs e)
        {
            textBoxName.Focus();
        }
        private void buttonSearch_Click(object sender, EventArgs e)
        {
            if (textBoxName.Text == "") { textBoxName.Focus(); return; }
            IList result = m_service.GetCustomerByNameList(textBoxName.Text.Trim());
            listViewResult.Items.Clear();
            if (result.Count == 0)
            {
                ListViewItem item = listViewResult.Items.Add("");
                item.SubItems.Add("Nothing found. " + DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss"));
            }
            else
            {
                foreach (acuheader acu in result)
                {
                    ListViewItem item = listViewResult.Items.Add(acu.apar_id);
                    item.SubItems.Add(acu.apar_name);
                    item.SubItems.Add(acu.client);
                    item.SubItems.Add(acu.apar_gr_id);
                    item.Tag = acu;
                }
            }
        }

        private void listViewResult_DoubleClick(object sender, EventArgs e)
        {
            if(listViewResult.SelectedItem==null)return;
            if(listViewResult.SelectedItem.Tag==null)return;
            acuheader acu = (acuheader)listViewResult.SelectedItem.Tag;
            m_parentForm.UpdateAgressoCustomer(acu);
            this.Close();
        }
        private void textBoxName_EnterKeyDown(object objSender, KeyEventArgs objArgs)
        {
            buttonSearch_Click(objSender, null);
        }
    }
}